package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingPlanDto;
import com.zzyl.service.NursingPlanService;
import com.zzyl.vo.NursingPlanVo;
import com.zzyl.vo.NursingProjectVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import io.swagger.models.auth.In;
import lombok.extern.slf4j.Slf4j;
import org.assertj.core.internal.IntArrays;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Primary;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Description NursingPlan
 * @Author hu hanSan
 * @Date 2024-09-08
 */
@RestController
@Slf4j
@RequestMapping(("/nursing"))
@Api(tags = "护理计划的接口")
public class NursingPlanController extends BaseController{
    @Autowired
    private NursingPlanService nursingPlanService;
    /**
     * 查询所有护理计划
     * @return
     */
    @ApiOperation(value = "查询所有的护理计划")
    @GetMapping("/plan")
  public ResponseResult<List<NursingPlanVo>> selectAllPlan(){
        List<NursingPlanVo>list= nursingPlanService.selectAllPlan();
        return success(list);
  }

    /**
     * 新增护理计划
     * @param nursingPlanDto
     * @return
     */
    @ApiOperation(value = "新增护理计划")
  @PostMapping("/plan")
    public ResponseResult addPlan(@RequestBody NursingPlanDto nursingPlanDto){
        nursingPlanService.addPlan(nursingPlanDto);
        return success();
  }

    /**
     * 条件分页查询
     * @return
     */
    @ApiOperation(value = "条件分页查询护理计划")
  @GetMapping("/plan/search")
    public ResponseResult<PageResponse<NursingPlanVo>> getByPage(
          @ApiParam(value = "护理计划名称") String name,
          @ApiParam(value = "状态0，1")Integer status,
          @ApiParam(value = "页码")@RequestParam(value = "pageNum",defaultValue = "1") Integer pageNum,
          @ApiParam(value = "每页展示数量")@RequestParam(value = "pageSize",defaultValue = "10") Integer pageSize

          ){
      PageResponse<NursingPlanVo>list= nursingPlanService.getByPage(name,status,pageNum,pageSize);
      return success(list);
  }

    /**
     * 根据id来查询护理计划
     * @param id
     * @return
     */
    @ApiOperation(value = "根据id来查询护理计划",notes = "传进来的id")
  @GetMapping("/plan/{id}")
  public ResponseResult<NursingPlanVo> selectById(@PathVariable("id")  Long id){
        NursingPlanVo nursingPlanVo= nursingPlanService.selectById(id);
        return success(nursingPlanVo);
  }

  @ApiOperation(value = "修改护理计划")
  @PutMapping("/plan/{id}")
  public ResponseResult update(@RequestBody NursingPlanDto nursingPlanDto){
        nursingPlanService.update(nursingPlanDto);
        return success();
  }

    /**
     * 删除护理计划
     * @param id
     * @return
     */
    @ApiOperation(value = "删除护理计划")
   @DeleteMapping("/plan/{id}")
    public ResponseResult delete(@PathVariable Long id){
        nursingPlanService.delete(id);
        return success();
    }

    @ApiOperation(value = "开启与禁用")
    @PutMapping("/plan/{id}/status/{status}")
    public ResponseResult updateStatus(@PathVariable Integer id ,@PathVariable Integer status){
        nursingPlanService.updateStatus(id,status);
        return success();
    }
}
